"use client" import * as React from 'react' import { useRouter } from 'next/navigation' import { StatusBadge } from '@open-mercato/ui/primitives/status-badge' import { SegmentedControl, SegmentedControlItem } from '@open-mercato/ui/primitives/segmented-control' import { Button } from '@open-mercato/ui/primitives/button' import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@open-mercato/ui/primitives/table' import { EmptyState } from '@open-mercato/ui/primitives/empty-state' import { useT } from '@open-mercato/shared/lib/i18n/context' import { ConfidenceFaceValue } from '../../../../components/cockpitStatus' import { formatTimeShort } from '../../../../components/types' import { buildRunRows, outcomeVariant, titleCase } from './workspaceShared' type Facet = 'all' | 'errors' | 'overridden' type ActivityTabProps = { runs: Array> proposals: Array> } export function ActivityTab({ runs, proposals }: ActivityTabProps) { const t = useT() const router = useRouter() const [facet, setFacet] = React.useState('all') const rows = React.useMemo(() => buildRunRows(runs, proposals), [runs, proposals]) const counts = React.useMemo( () => ({ all: rows.length, errors: rows.filter((row) => row.outcome === 'failed').length, overridden: rows.filter((row) => row.outcome === 'overridden').length, }), [rows], ) const filtered = rows.filter((row) => { if (facet === 'errors') return row.outcome === 'failed' if (facet === 'overridden') return row.outcome === 'overridden' return true }) const open = (id: string) => router.push(`/backend/traces/${encodeURIComponent(id)}`) return (
setFacet(value as Facet)} aria-label={t('agent_orchestrator.agentDetail.activity.filter', 'Filter runs')}> {t('agent_orchestrator.agentDetail.activity.facetAll', 'All')} ({counts.all}) {t('agent_orchestrator.agentDetail.activity.facetErrors', 'Errors')} ({counts.errors}) {t('agent_orchestrator.agentDetail.outcome.overridden', 'Overridden')} ({counts.overridden})
{filtered.length === 0 ? ( ) : (
{t('agent_orchestrator.agentDetail.recent.claim', 'Claim')} {t('agent_orchestrator.agentDetail.recent.decision', 'Decision')} {t('agent_orchestrator.agentDetail.recent.conf', 'Conf.')} {t('agent_orchestrator.agentDetail.recent.outcome', 'Outcome')} {t('agent_orchestrator.agentDetail.recent.when', 'When')} {filtered.map((run) => ( open(run.id)} onKeyDown={(event) => { if (event.key === 'Enter' || event.key === ' ') { event.preventDefault() open(run.id) } }} > {run.claim} {run.decision} {t(`agent_orchestrator.agentDetail.outcome.${run.outcome}`, titleCase(run.outcome))} {formatTimeShort(run.when) ?? ''} ))}
)}
) }